import Vue from 'vue'
import VueRouter from 'vue-router'
import storage from '@/utils/storage'
import staticRoutes from '@/router/routerMap/staticRoutes'
import store from "@/store";
Vue.use(VueRouter)

// const router = new VueRouter({
//     routes:staticRoutes
// })

export function createRouter(routes){
    return new VueRouter({
        routes
    })
}

const router = createRouter(staticRoutes)





router.beforeEach((to,from,next)=>{
    let token = storage.token
    if(token){
        next()
    }else{
        if(to.path === '/login'){
            next()
        }else{
            router.replace('/login')
        }
    }
})

export default router

store.commit('permission/updata_matcher')
